#include "robolite.h"

//RoboLite sensor support functions implementation file

#if USE_ANALOG||FULL_CODE
uint rl_getAnalog(char port)
{
    #warning "rl_getAnalog compiled."
    uint addata;
    rl_clearBit(DDRC,port);
    rl_clearBit(PORTC,port);

    ADMUX=port;

    //reference voltage settings
    rl_setBit(ADMUX,REFS0);
//  rl_setBit(ADMUX,REFS1);

    rl_setBit(ADCSRA,ADEN);
    rl_setBit(ADCSRA,ADSC);

    while(!(ADCSRA&(BIT(ADIF))));

    addata=ADCL;
    addata=addata+ADCH*256;
    return addata;

}



int rl_impact_analog(char x)
{
    #warning "rl_impact_analog compiled."
    uint adval;
    adval=rl_getAnalog(x);
    if(adval<850)
    {
        //impacted
        return 1;
    }
    else
    {
        return 0;
    }
}

#endif


int rl_impact_digi(char x)
{
    #warning "rl_impact_digi compiled."
    return !rl_getBit(PINC,x);  //return true if in sight
}


